From 41d039a327a6a9254a1580699188413a7e7363af Mon Sep 17 00:00:00 2001
From: Elie ROUDNINSKI <xademax@gmail.com>
Date: Sun, 7 Oct 2018 18:02:24 +0100
Subject: [PATCH] Support custom c(cld)flags for CC(LD)_FOR_BUILD

---
 Make.defaults | 11 +++++++++++
 src/Makefile  |  1 +
 2 files changed, 12 insertions(+)

diff --git a/Make.defaults b/Make.defaults
index 57cee6e..814b0ef 100644
--- a/Make.defaults
+++ b/Make.defaults
@@ -36,6 +36,11 @@ cflags	= $(CFLAGS) -I${TOPDIR}/src/include/ \
 	$(if $(findstring ccc-analyzer,$(CC)),$(clang_cflags),) \
 	$(if $(findstring gcc,$(CC)),$(gcc_cflags),) \
 	$(call pkg-config-cflags)
+cflags_for_build	= $(BUILD_CFLAGS) -I${TOPDIR}/src/include/ \
+	$(if $(findstring clang,$(CC_FOR_BUILD)),$(clang_cflags),) \
+	$(if $(findstring ccc-analyzer,$(CC_FOR_BUILD)),$(clang_cflags),) \
+	$(if $(findstring gcc,$(CC_FOR_BUILD)),$(gcc_cflags),) \
+	$(call pkg-config-cflags)
 clang_ccldflags =
 gcc_ccldflags =
 ccldflags = $(cflags) -L. $(CCLDFLAGS) $(LDFLAGS) \
@@ -44,6 +49,12 @@ ccldflags = $(cflags) -L. $(CCLDFLAGS) $(LDFLAGS) \
 	$(if $(findstring ccc-analyzer,$(CCLD)),$(clang_ccldflags),) \
 	$(if $(findstring gcc,$(CCLD)),$(gcc_ccldflags),) \
 	$(call pkg-config-ldflags)
+ccldflags_for_build = $(cflags_for_build) -L. $(BUILD_CCLDFLAGS) $(BUILD_LDFLAGS) \
+	-Wl,-z,muldefs \
+	$(if $(findstring clang,$(CCLD_FOR_BUILD)),$(clang_ccldflags),) \
+	$(if $(findstring ccc-analyzer,$(CCLD_FOR_BUILD)),$(clang_ccldflags),) \
+	$(if $(findstring gcc,$(CCLD_FOR_BUILD)),$(gcc_ccldflags),) \
+	$(call pkg-config-ldflags)
 SOFLAGS=-shared
 LDLIBS=$(foreach lib,$(LIBS),-l$(lib)) $(call pkg-config-ldlibs)
 
diff --git a/src/Makefile b/src/Makefile
index 76bc474..287bb1d 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -56,6 +56,7 @@ makeguids : CPPFLAGS+=-DEFIVAR_BUILD_ENVIRONMENT
 makeguids : LIBS=dl
 makeguids : $(MAKEGUIDS_SOURCES)
 makeguids : CCLD=$(CCLD_FOR_BUILD)
+makeguids : ccldflags=$(ccldflags_for_build)
 
 guids.o : guids.S | guids.bin names.bin
 
-- 
2.19.0

